﻿//变量全部可配置，可存储自定义内容


//var list = new CtnListCtrl("list");
//function init()
//{
//    var xmlInfo = '<items caption="中国电信" badd="0" bedit="1" bscheck="1" bdel="0" totalcount="100" bpage="0" pagesize="10" curpage="1">'
//        + '<colnames>'
//            + '<ID0 visible="0">ID0</ID0>'
//            + '<Bm bedit="0">编码</Bm>'
//            + '<Mc visible="1" bedit="0">名称</Mc>'
//            + '<group inputtype="select">部门<select><option value="01">电信</option><option value="02">市政</option><option value="01">国土</option></select></group>'
//            + '<time addvalue="2007">时间</time>'
//        + '</colnames>'
//        + '<item><ID0>10001</ID0><Bm>bm01</Bm><Mc>名称01</Mc><group>电信</group><time>2007-01</time></item>'
//        + '<item><ID0>10002</ID0><Bm>bm02</Bm><Mc>名称02</Mc><group>电信</group><time>2007-02</time></item>'
//        + '<item><ID0>10003</ID0><Bm>bm03</Bm><Mc>名称03</Mc><group>国土</group><time>2007-03</time></item>'
//        + '<item><ID0>10004</ID0><Bm>bm04</Bm><Mc>名称04</Mc><group>国土</group><time>2007-04</time></item>'
//        + '<item><ID0>10005</ID0><Bm>bm05</Bm><Mc>名称05</Mc><group>市政</group><time>2007-05</time></item>'
//        + '<item><ID0>10006</ID0><Bm>bm06</Bm><Mc>名称06</Mc><group>市政</group><time>2007-06</time></item>'
//        + '</items>';
//    list.create("ls");
//    list.onGoPage = function (pageno)
//    {
//        this.reset();
//        this.insertXml(xmlInfo, 1);
//        for (var i = 0; i < list.arrRow.length; i++)
//        {
//            this.getCell(i, 1).text = '<a href="#" >' + this.getCell(i, 1).text + '</a>';//
//        }
//        this.show();
////        this.getRow(0).getCell("ID0").text;
//    }
//    list.goPage(1);
//}

//行对象


function RowInfo(parent, id)
{
    this.parent     = parent;
    this.id         = id;   //行ID
    this.bchecked   = 0;    //是否选择
    this.arrCell    = new Array();
    this.append     = function (cell){this.arrCell.push(cell);}
    this.remove     = function (pos){this.arrCell.splice(pos, 1);}
    this.update     = function (pos, cell){this.arrCell[pos] = cell;}
    this.getCell    = function (name)
                    {
                        var arrCol = this.parent.arrCol;
                        for(var k in arrCol)
                        {
                            if(arrCol[k].name == name)
                            {
                                return this.arrCell[k];
                            }
                        }
                        return null;
                    }
}
//列对象


function ColInfo(parent, id, name, text)
{
    this.parent     = parent;
    this.id         = id;   //ID
    this.name       = name; //节点名称
    this.text       = text; //标题
    this.visible    = 1;    //是否可视
    this.bedit      = 1;    //是否可编辑


    this.inputtype  ="text";    //input 类型
    this.arrOption  = new Array();  //select列表框数据


    this.addvalue   = "";   //添加初始化值


    this.maxsize    = -1;   //该列最大宽
    this.order      = 1;    //排序:-1降序,0未排序,1升序
}

//单元对象
function CellInfo(parent, id,text)
{
    this.parent = parent;
    this.id     = id;   //单元ID
    this.text   = text; //该列的值
}

function CtnListCtrl(listname)
{
    this.listname   = listname; //变量名


    this.listid     = null;     //DIV id
    this.doc        = null;     //文档对象
    
    this.arrRow     = new Array();  //存储行信息
    this.arrData    = new Array();  //存储访问过的分页结果

    this.arrCol     = new Array();  //存储列信息


    
    //根节点属性


    this.caption    = null; //标题
    this.minsize    = 500;   //表格最小宽度


    this.bpage      = 0;
    this.totalcount = -1;   //总纪录


    this.pagesize   = 10;   //每页大小
    this.curpage    = 0;    //当前页    this.bsave      = 1;    //是否保存分页结果


    this.bcheck     = 0;    //可选择
    this.badd       = 0;    //可添加

    this.bscheck    = 0;    //单选

    this.bedit      = 0;    //可编辑
    this.ballcheck  = 1;    //可全选

    this.bdel       = 0;    //可删除

    this.bfill      = 0;   //自动填充
    
    this.fontsize   = 14;   //字体大小
    this.offset     = 2;    //单元调整值


    this.tablestyle     = "listctrl";   //list主样式


    this.captionstyle   = "caption";
    this.colstyle       = "title";
    this.coloverstyle   = "colover";
    this.colselstyle    = "colsel";
    this.srowstyle      = "srow";
    this.drowstyle      = "drow";
    this.rowoverstyle   = "rowover";
    this.rowselstyle    = "rowsel";
    this.cellselstyle   = "cellsel";
    this.rowaddstyle    = "rowadd";
    this.roweditstyle    = "rowedit";
    this.rowpagestyle   = "rowpage";
    
        
    //公用函数
    this.insertXml    = insertXml_LC;   //根据XML文本(xmlinfo)
    this.insertNode   = insertNode_LC;  //根据XML节点对象(response.responseXML);
    this.create         = create_LC;        //初始化(listid, window)
    this.show           = show_LC;          //显示
    this.reset          = reset_LC;         //重置
    this.resetFlow      = resetFlow_LC;     //重新调整宽高
    
    this.getTableid     = getTableid_LC; //获取表格ID
    this.getCaptionid   = getCaptionid_LC;//获取表头ID
    this.getColid       = getColid_LC;  //根据列号获取列ID(colno) (return colid)
    this.getRowid       = getRowid_LC;  //根据行号获取行ID(rowno) (return rowid)
    this.getCellid      = getCellid_LC; //根据行号列号获取单元ID(rowno, colno) (return cellid)
    this.getColno       = getColno_LC;  //根据列ID获取列号(id) (return colno)
    this.getRowno       = getRowno_LC;  //根据行ID获取行号(id) (return rowno)
    this.getCellno      = getCellno_LC; //根据单元ID获取行号列号(id) (return {rowno:rowno,colno:colno})
    this.getCol         = getCol_LC;    //根据列号获取列对象(colno) (return col)
    this.getRow         = getRow_LC;    //根据行号获取行对象(rowno) (return row)
    this.getCell        = getCell_LC;   //根据行号列号获取单元对象(rowno, colno) (return cell)
    
    this.setStyle       = setStyle_LC;   //设置样式(id,className)
    this.setStyleObj    = setStyleObj_LC;//设置样式对象(id, styleObj)
    
//    this.setTableStyle  = setTableStyle_LC;   //设置行样式(className)
//    this.setTableStyleObj   = setTableStyleObj_LC;//设置行样式对象(styleObj)
//    this.setRowStyle    = setRowStyle_LC;   //设置行样式(rowno, className)
//    this.setRowStyleObj = setRowStyleObj_LC;//设置行样式对象(rowno, styleObj)
//    this.setColStyle    = setColStyle_LC;   //设置行样式(colno, className)
//    this.setColStyleObj = setColStyleObj_LC;//设置行样式对象(colno, styleObj)
//    this.setCellStyle   = setCellStyle_LC;   //设置行样式(rowno, colno, className)
//    this.setCellStyleObj    = setCelltyleObj_LC;//设置行样式对象(rowno, colno, styleObj)
    
    this.setCheck       = setCheck_LC;  //设置选择(rowno, bcheck)
    this.setAllChecked  = setAllChecked_LC; //全选
    this.setAllUnChecked= setAllUnChecked_LC;   //全不选
    this.getCheckedArr  = getCheckedArr_LC; //获取所选行号数组(return arrRowno)
    this.setCheckedArr  = setCheckedArr_LC; //根据行号数组设置(arrRowno)
    
    //事件接口
    this.onColClick     = null; //列左键单击(evt, colno)
    this.onColRClick    = null; //列右键单击(evt, colno)
    this.onColDblClick  = null; //列左键双击(evt, colno)
    this.onRowClick     = null; //行左键单击(evt, rowno)
    this.onRowRClick    = null; //行右键单击(evt, rowno)
    this.onRowDblClick  = null; //行左键双击(evt, rowno)
    this.onCellClick    = null; //单元左键单击(evt, rowno, colno)
    this.onCellRClick   = null; //单元右键单击(evt, rowno, colno)
    this.onCellDblClick = null; //单元左键双击(evt, rowno, colno)
    
    this.onAdd          = null; //添加(newRow)
    this.onDel          = null; //删除(rowno)
    this.onEdit         = null; //编辑(rowno)
    this.onUpdate       = null; //更新(rowno, newRow)
    this.onCancel       = null; //取消(rowno)
    this.onCheck        = null; //选择(rowno)
    this.onDelChecked   = null; //删除所选(arrRowno)
    this.onCheckToggle  = null; //全选(bcheck)
    this.onGoPage       = null; //跳转页(pageno)
    
    //this.onShowMsg      = null; //消息提示(msg)
    
    //内部变量
    this.oldrowstyle    = "";
    this.oldcolstyle    = "";
    this.selRow         = -1;
    this.selCol         = -1;
    this.totalpage      = -1;
    
    //内部函数
    this.calTextSize    = calTextSize_LC;   //计算字符串像素大小


    this.setCellSel     = setCellSel_LC;     //设置行选中风格
    this.getColHtml     = getColHtml_LC;
    this.getRowHtml     = getRowHtml_LC;
    this.getFootHtml    = getFootHtml_LC;
    this.getListHtml    = getListHtml_LC;
    this.getPageHtml    = getPageHtml_LC;
    
    this.colClick       = colClick_LC;
    this.colRClick      = colRClick_LC;
    this.colDblClick    = colDblClick_LC;
    this.rowClick       = rowClick_LC;
    this.rowRClick      = rowRClick_LC;
    this.rowDblClick    = rowDblClick_LC;
    this.cellClick      = cellClick_LC;
    this.cellRClick     = cellRClick_LC;
    this.cellDblClick   = cellDblClick_LC;
    this.rowOver        = rowOver_LC;
    this.rowOut         = rowOut_LC;
    this.colOver        = colOver_LC;
    this.colOut         = colOut_LC;
        
    this.listAdd        = listAdd_LC;
    this.listDel        = listDel_LC;
    this.listEdit       = listEdit_LC;
    this.listUpdate     = listUpdate_LC;
    this.listCancel     = listCancel_LC;
    this.listCheck      = listCheck_LC;
    this.listDelChecked = listDelChecked_LC;
    this.listCheckToggle= listCheckToggle_LC;
    this.setCommand     = setCommand_LC;
    this.goPage         = goPage_LC;
    
    //xml操作
    this.getXmlDoc      = getXmlDoc_LC;
    this.clearSpace     = clearSpace_LC;
    this.$XML           = $XML_LC;
    this.$              = $_LC;
    
    this.showMsg        = showMsg_LC;
}
///////////错误处理//////////////
function showMsg_LC(msg)
{
    if (this.onShowMsg)
    {
        this.onShowMsg(msg);
    }
    else
    {
        alert(msg);
    }
}
/////////样式风格处理///////////
function setStyle_LC(id, className)
{
    this.tablestyle = className;
    var elem = this.$(id);
    if (elem)
    {
        elem.className += className;
    }
}
function setStyleObj_LC(id, styleObj)
{
    var elem = this.$(id);
    if (elem)
    {
        for (var key in styleObj)
        {
            elem.style[key] = styleObj[key];
        }
    }
}

//function setTableStyle_LC(className)
//{
//    this.tablestyle = className;
//    var elem = this.$(this.getTableid());
//    if (elem)
//    {
//        elem.className += className;
//    }
//}
//function setTableStyleObj_LC(styleObj)
//{
//    var elem = this.$(this.getTableid());
//    if (elem)
//    {
//        for (var key in styleObj)
//        {
//            elem.style[key] = styleObj[key];
//        }
//    }
//}
//function setRowStyle_LC(className)
//{
//    this.tablestyle = className;
//    var elem = this.$(this.getRowid(rowno));
//    if (elem)
//    {
//        elem.className += className;
//    }
//}
//function setRowStyleObj_LC(rowno, styleObj)
//{
//    this.tablestyle = className;
//    var elem = this.$(this.getRowid(rowno));
//    if (elem)
//    {
//        for (var key in styleObj)
//        {
//            elem.style[key] = styleObj[key];
//        }
//    }
//}
//////////表格编辑/////////////
function listAdd_LC(btn)
{
    var tr = btn.parentNode.parentNode;
    //提取放到Row对象中


    var arrBtn = tr.getElementsByTagName("input");
    var rowno = this.arrRow.length;
    var newRow = new RowInfo(this, this.getRowid(rowno));
    for (var i = 0; i < this.arrCol.length; i++)
    {
        var elem = this.$(this.listid + '_add_' + i);
        var cellText = elem.value;
        if (this.arrCol[i].inputtype == "select")
        {
            cellText = elem.options[elem.selectedIndex].innerHTML;
        }
//        var textsize = this.calTextSize(cellText);
//        if (this.arrCol[i].maxsize < textsize)
//        {
//            this.arrCol[i].maxsize = textsize;
//        }
        var newCell = new CellInfo(newRow, this.getCellid(rowno, i), cellText);
        newRow.append(newCell);
    }
    if (this.onAdd)
    {
        //返回值为false时，代表不更新


        if (!this.onAdd(newRow))
        {
            return;
        }
    }
    //将newRow存放，并显示
    this.arrRow.push(newRow);
    this.show();
}
function listDel_LC(btn, rowno)
{
    if (confirm("确定删除？"))
    {
        var tr = btn.parentNode.parentNode;
        var nextTR = tr.nextSibling;
        if (nextTR)
        {
            var arrBtn = nextTR.getElementsByTagName("input");
            if (arrBtn[0].value == "更新")
            {
                nextTR.parentNode.removeChild(nextTR);
            }
        }
        if (this.onDel)
        {
            if (!this.onDel(rowno))
            {
                return;
            }
        }
        //解决选中问题
        if (this.selRow >= rowno)
        {
            this.selRow = -1;
        }
        this.arrRow.splice(rowno, 1);
        this.show();
    }
}
function listEdit_LC(btn, rowno)
{
    btn.disabled=true;
    var tr = btn.parentNode.parentNode;
    this.clearSpace(tr);
    if (this.onEdit)
    {
        if (!this.onEdit(rowno))
        {
            return;
        }
    }
    var tbody = tr.parentNode;
    this.clearSpace(tbody);
    //var table = tbody.parentNode;
    var idx = 0;
    while(tbody.childNodes[idx] != tr)
    {
        idx++;
    }
    idx++;
    var newTR = tbody.insertRow(idx);
    newTR.className = this.roweditstyle;
    var newTD = newTR.insertCell(0);
    newTD.innerHTML = '<input type="button" onclick="' + this.listname + '.listUpdate(this, ' + rowno + ');" value="更新" />'
                     + '<input type="button" onclick="' + this.listname + '.listCancel(this, ' + rowno + ');" value="取消" />';
    
    for (var i = 0; i< this.arrCol.length; i++)
    {
        var vHtml = new String();
        if (this.arrCol[i].inputtype == "select")
        {
            vHtml += '<select';
            vHtml += ' id="' + this.listid + '_ed_' + rowno + '_' + i + '"';
            vHtml += ' style="width:' + (this.arrCol[i].maxsize*1 + 22) + 'px;"';
            if (!this.arrCol[i].bedit)
            {
                vHtml += ' disabled="disabled"';
            }
            vHtml += '>';
            var arrOption = this.arrCol[i].arrOption;
            for (var j = 0; j < arrOption.length; j++)
            {
                if (arrOption[j].text == this.arrRow[rowno].arrCell[i].text)
                {
                    vHtml += '<option value="' + arrOption[j].value + '" selected="selected">';
                }
                else
                {
                    vHtml += '<option value="' + arrOption[j].value + '">';
                }
                vHtml += arrOption[j].text + '</option>';
            }
            vHtml += '</select>';
        }
        else
        {
            vHtml += '<input type="text"';
            vHtml += ' id="' + this.listid + '_ed_' + rowno + '_' + i + '"';
            vHtml += ' value="' + this.arrRow[rowno].arrCell[i].text.replace(/\</g,"&lt;").replace(/\>/g,"&gt;").replace(/\"/g, "'") + '"';
            vHtml += ' style="width:' + this.arrCol[i].maxsize + 'px;"/>';
        }
        newTD = newTR.insertCell(i*1 + 1);
        if (!this.arrCol[i].visible)
        {
            newTD.style.display = "none";
        }
        newTD.innerHTML = vHtml;
    }
}
function listUpdate_LC(btn, rowno)
{
    var tr = btn.parentNode.parentNode;
    var arrBtn = tr.getElementsByTagName("input");
    var oldRow = this.arrRow[rowno];
    var newRow = new RowInfo(this);
    //拷贝属性


    for (var key in oldRow)
    {
        newRow[key] = oldRow[key];
    }
    newRow["arrCell"] = new Array();//数组
    for (var i = 0; i < this.arrCol.length; i++)
    {
        var elem = this.$(this.listid + '_ed_' + rowno + '_' + i);
        var cellText = elem.value;
        if (this.arrCol[i].inputtype == "select")
        {
            cellText = elem.options[elem.selectedIndex].innerHTML;
        }
//        var textsize = this.calTextSize(cellText);
//        if (this.arrCol[i].maxsize < textsize)
//        {
//            this.arrCol[i].maxsize = textsize;
//        }
        var newCell = new CellInfo();
        //拷贝属性


        for (var key in oldRow.arrCell[i])
        {
            newCell[key] = oldRow.arrCell[i][key];
        }
        newCell["text"] = cellText;
        newRow.append(newCell);
    }
    if (this.onUpdate)
    {
        //返回值为false时，代表不更新


        if (!this.onUpdate(rowno, newRow))
        {
            return;
        }
    }
    this.arrRow[rowno] = newRow;
    this.show();
}
function listCancel_LC(btn, rowno)
{
    if (this.onCancel)
    {
        //返回值为false时，代表不更新


        if (!this.onCancel(rowno))
        {
            return;
        }
    }
    var tr = btn.parentNode.parentNode;
    var preTR = tr.previousSibling;
    var arrBtn = preTR.getElementsByTagName("input");
    arrBtn[1].disabled = false;
    tr.parentNode.removeChild(tr);
}
function setCommand_LC()
{
    if (!this.bcheck && !this.bdel && !this.bedit)
    {
        return;
    }
    var div = this.$(this.listid);
    var arrElem = div.getElementsByTagName("input");
    for (var i = 0; i < arrElem.length; i++)
    {
        if ((this.bedit)
            && (arrElem[i].type == "button")
            && (arrElem[i].value == "编辑"))
        {
            arrElem[i].style.display = "";
        }
        else if ((this.bdel)
            && (arrElem[i].type == "button")
            && (arrElem[i].value == "删除"))
        {
            arrElem[i].style.display = "";
        }
        else if ((this.bcheck)
            && (arrElem[i].type == "checkbox"))
        {
            arrElem[i].style.display = "";
        }
    }
    if (this.bcheck || this.bdel || this.bedit)
    {
        var tbody = this.$(this.listid + "_tbody");
        for (var i = 0; i < tbody.childNodes.length; i++)
        {
            tbody.childNodes[i].childNodes[0].style.display = "";
        }
    }
    if (this.badd)
    {
        var tfoot = this.$(this.listid + "_tfoot");
        tfoot.childNodes[0].style.display = "";
    }
    var cmd = this.$(this.listid + "_cmd");
    cmd.style.display = "";
}

function goPage_LC(num)
{
    if (!this.onGoPage)
    {
        return;
    }
    if(num == null)
    {
        num = parseInt(this.$(this.listid + "_pagenum").value);
        if (isNaN(num))
        {
            this.showMsg("请填写数字！");
            return;
        }
    }
    if (num > this.totalpage)
    {
        num = this.totalpage;
    }
    if(num < 1)
    {
        num = 1;
    }
    if (this.bsave)
    {
        this.arrData[this.curpage] = this.arrRow;
        //已访问过，则直接取
        if (this.arrData[num] != null)
        {
            this.arrRow = this.arrData[num];
            this.curpage = num;
            this.show();
        }
        else
        {
            this.curpage = num;
            this.arrRow = new Array();
            this.onGoPage(num);
        }
    }
    else
    {
        this.curpage = num;
        this.onGoPage(num);
    }
    
}
/////////////////////////checkbox/////////
function listCheck_LC(btn, rowno)
{
    if (btn.checked)
    {
        this.arrRow[rowno].bchecked = 1;
    }
    else
    {
        this.arrRow[rowno].bchecked = 0;
    }
    
    if (this.bscheck)
    {
        for (var i = 0; i < this.arrRow.length; i++)
        {
            if (i != rowno && this.arrRow[i].bchecked)
            {
                this.arrRow[i].bchecked = 0;
                var arrElem = this.$(this.getRowid(i)).getElementsByTagName("input");
                for (var j = 0; j < arrElem.length; j++)
                {
                    if (arrElem[j].type == "checkbox")
                    {
                        arrElem[j].checked = false;
                    }
                }
            }
        }
    }
    
    if (this.onCheck)
    {
        if (!this.onCheck(rowno, btn.checked))
        {
            //btn.checked = !btn.checked;
            return;
        }
    }
}

function listDelChecked_LC()
{
    if (!confirm("确定删除所选?"))
    {
        return;
    }
    var arrRowno = this.getCheckedArr();
    if (this.onDelChecked)
    {
        if (!this.onDelChecked(arrRowno))
        {
            return;
        }
    }
    for (var i = arrRowno.length - 1; i >=0 ; i--)
    {
        this.arrRow.splice(arrRowno[i], 1);
    }
    this.show();
}

function listCheckToggle_LC(btn)
{
    if (this.onCheckToggle)
    {
        if (!this.CheckToggle(btn.checked))
        {
            btn.checked = !btn.checked;
            return;
        }
    }
    if (btn.checked)
    {
        this.setAllChecked();
    }
    else
    {
        this.setAllUnChecked();
    }
}
function setCheck_LC(rowno, flag)
{
    this.arrRow[rowno].bchecked = flag?1:0;
    var elem = this.$(this.listid + "_ckb_" + rowno);
    elem.checked = flag;
}
function setAllChecked_LC()
{
    for (var i = 0; i < this.arrRow.length; i++)
    {
        this.setCheck(i, true);
    }
}
function setAllUnChecked_LC()
{
    for (var i = 0; i < this.arrRow.length; i++)
    {
        this.setCheck(i, false);
    }
}

function getCheckedArr_LC()
{
    var arrRowno = new Array();
    for (var i = 0; i < this.arrRow.length; i++)
    {
        if (this.arrRow[i].bchecked)
        {
            arrRowno.push(i);
        }
    }
    return arrRowno;
}

function setCheckedArr_LC(arrRowno)
{
    for (var i = 0; i < this.arrRowno.length; i++)
    {
        this.setCheck(arrRowno[i], true);
    }
}
////////////////////////////////
function getTableid_LC()
{
    return this.listid + "table";
}
function getCaptionid_LC()
{
    return this.listid + "caption";
}
function getRowid_LC(rowno)
{
    return this.listid + "_row_" + rowno;
}

function getColid_LC(colno)
{
    return this.listid + "_col_" + colno;
}

function getCellid_LC(rowno, colno)
{
    return this.listid + "_" + rowno + "_" + colno;
}
function getRowno_LC(rowid)
{
    var rowno = 0;
    for (var i = 0; i < this.arrRow.length; i++)
    {
        if (this.arrRow[i].id == rowid)
        {
            rowno = i;
            break;
        }
    }
    return rowno;
}

function getColno_LC(colid)
{
    var colno = 0;
    for (var i = 0; i < this.arrCol.length; i++)
    {
        if (this.arrCol[i].id == colid)
        {
            colno = i;
            break;
        }
    }
    return colno;
}

function getCellno_LC(cellid)
{
    var rowno = 0;
    var colno = 0;
    for (var i = 0; i < this.arrRow.length; i++)
    {
        var arrCell = this.arrRow[i].arrCell;
        for (var j = 0; j < arrCell.length; j++)
        {
            if (arrCell[j].id == cellid)
            {
                rowno = i;
                colno = j;
                break;
            }    
        }
    }
    return {rowno:rowno,colno:colno};
}

function getRow_LC(rowno)
{
    return this.arrRow[rowno];
}

function getCol_LC(colno)
{
    return this.arrCol[colno];
}

function getCell_LC(rowno, colno)
{
    return this.arrRow[rowno].arrCell[colno];
}
////////////
function setCellSel_LC(row, col)
{
    var selElem = null;
    if (this.selRow > -1)
    {
        selElem = this.$(this.arrRow[this.selRow].id);
        if (this.selRow % 2)
        {
            selElem.className = this.drowstyle;
        }
        else
        {
            selElem.className = this.srowstyle;
        }
    }
    if (row > -1)
    {
        selElem = this.$(this.arrRow[row].id);
        selElem.className = this.rowselstyle;
        this.oldrowstyle  = this.rowselstyle;
    }
    
    if (this.selCol > -1)
    {
        selElem = this.$(this.arrCol[this.selCol].id);
        selElem.className = this.colstyle;
    }
    if (col > -1)
    {
        selElem = this.$(this.arrCol[col].id);
        selElem.className = this.colselstyle;
        this.oldcolstyle  = this.colselstyle;
    }


    if (this.selRow > -1 && this.selCol > -1)
    {
        selElem = this.$(this.arrRow[this.selRow].arrCell[this.selCol].id);
        selElem.className = "";
    }
    if (row > -1 && col > -1)
    {
        selElem = this.$(this.arrRow[row].arrCell[col].id);
        selElem.className = this.cellselstyle;
    }

    this.selRow = row;
    this.selCol = col;
}

///////////响应事件/////////////
function colClick_LC(evt, colno)
{
    this.setCellSel(this.selRow, colno);
    if (this.onColClick)
    {
        this.onColClick(evt, colno);
    }
}
function colRClick_LC(evt, colno)
{
    this.setCellSel(this.selRow, colno);
    if (this.onColClick)
    {
        this.onColClick(evt, colno);
    }
}
function colDblClick_LC(evt, colno)
{
    this.setCellSel(this.selRow, colno);
    if (this.onColClick)
    {
        if(!this.onColClick(evt, colno))
        {
            return;
        }
    }
    if (this.arrCol[colno].order == 1)
    {
        this.arrCol[colno].order = -1;
    }
    else if(this.arrCol[colno].order == -1)
    {
        this.arrCol[colno].order = 1;
    }
    else
    {
        return;
    }
    for (var i = 0; i < this.arrRow.length - 1; i++)
    {
        for (var j = i + 1; j < this.arrRow.length; j++)
        {
            if (((this.arrRow[i].arrCell[colno].text > this.arrRow[j].arrCell[colno].text)
                && (this.arrCol[colno].order == 1))
                ||((this.arrRow[i].arrCell[colno].text < this.arrRow[j].arrCell[colno].text)
                &&(this.arrCol[colno].order == -1)))
            {
                var tmprow = this.arrRow[i];
                this.arrRow[i] = this.arrRow[j];
                this.arrRow[j] = tmprow;
                if (this.selRow == i)
                {
                    this.selRow = j;
                }
                else if (this.selRow == j)
                {
                    this.selRow = i;
                }
            }
        }
    }
    this.show();
}
function rowClick_LC(evt, rowno)
{
    this.setCellSel(rowno, this.selCol);
    if (this.onRowClick)
    {
        this.onRowClick(evt, rowno);
    }
}
function rowRClick_LC(evt, rowno)
{
    this.setCellSel(rowno, this.selCol);
    if (this.onRowRClick)
    {
        this.onRowRClick(evt, rowno);
    }
}
function rowDblClick_LC(evt, rowno)
{
    this.setCellSel(rowno, this.selCol);
    if (this.onRowDblClick)
    {
        this.onRowDblClick(evt, rowno);
    }
}
function cellClick_LC(evt, rowno, colno)
{
    this.setCellSel(rowno, colno);
    if (this.onCellClick)
    {
        this.onCellClick(evt, rowno, colno);
    }
}
function cellRClick_LC(evt, rowno, colno)
{
    this.setCellSel(rowno, colno);
    if (this.onCellRClick)
    {
        this.onCellRClick(evt, rowno, colno);
    }
}
function cellDblClick_LC(evt, rowno, colno)
{
    this.setCellSel(rowno, colno);
    if (this.onCellDblClick)
    {
        this.onCellDblClick(evt, rowno, colno);
    }
}
function rowOver_LC(elem, row)
{
    this.oldrowstyle = elem.className;
    elem.className = this.rowoverstyle;
}
function rowOut_LC(elem, row)
{
    elem.className = this.oldrowstyle;
    this.oldrowstyle = "";
}
function colOver_LC(elem, col)
{
    this.oldcolstyle = elem.className;
    elem.className = this.coloverstyle;
}
function colOut_LC(elem, col)
{
    elem.className = this.oldcolstyle;
    this.oldcolstyle = "";
}
//////////////////显示部分////////////////
function create_LC(id, win)
{
    this.listid = id;
    this.doc = win?win.document:window.document;
}
function show_LC()
{
    var div = this.$(this.listid);
    div.innerHTML="";
    //div.style.width = (div.offsetWidth - 2) + "px";
    var elemBody = document.createElement("div");
//    var elemHead = elemBody.cloneNode(false);
//    var elemFoot = elemHead.cloneNode(false);
//    var elemTop = elemHead.cloneNode(false);
//    var elemBottom = elemHead.cloneNode(false);
    var elemPage = elemBody.cloneNode(false);

//    div.appendChild(elemTop);//补空白的
//    div.appendChild(elemHead);
    div.appendChild(elemBody);
//    div.appendChild(elemFoot);
//    div.appendChild(elemBottom);//补空白的
    div.appendChild(elemPage);
    
    elemBody.innerHTML = this.getListHtml();
    
    this.setCommand();
    this.setCellSel(this.selRow, this.selCol);
    
    //设足够大，使得table可以自适应
    elemBody.style.width = "30000px";
    
    var theadtr = elemBody.firstChild.childNodes[1].firstChild;
    if (this.arrRow.length > 0)
    {
        var tbodytr = elemBody.firstChild.childNodes[2].firstChild;
    }
    var tfoottr = elemBody.firstChild.childNodes[3].firstChild;
    
    //隐藏pageinfo,纯粹是为了使命令列固定(在pageinfo比数据长时)
//    if (this.totalcount != -1 || this.bpage==1)
//    {
//        elemBody.firstChild.childNodes[3].lastChild.style.display = "none";
//    }
    var cmdWidth = theadtr.childNodes[0].offsetWidth;
    theadtr.childNodes[0].style.width = cmdWidth + "px";
    if (this.arrRow.length > 0)
    {
        tbodytr.childNodes[0].style.width = cmdWidth + "px";
    }
    tfoottr.childNodes[0].style.width = cmdWidth + "px";
//    if (this.totalcount != -1 || this.bpage==1)
//    {
//        elemBody.firstChild.childNodes[3].lastChild.style.display = "";
//    }
//    if (this.badd)
//    {
//        for (var i = 1; i < tfoottr.childNodes.length; i++)
//        {
//            tfoottr.childNodes[i].firstChild.style.display = "none";//隐藏input，默认时可能比数据长
//        }
//    }
    
//    for (var i = 1; i < theadtr.childNodes.length; i++)
//    {
//        var width = theadtr.childNodes[i].offsetWidth;
//        if (width == 0)
//        {
//            continue;
//        }
//        if (this.arrCol[i - 1].inputtype == "select")
//        {
//            width += 24;
//        }
//        width = Math.max(this.arrCol[i - 1].maxsize, width);
//        this.arrCol[i - 1].maxsize = width;
//        theadtr.childNodes[i].style.width = width + "px";
//        if (this.arrRow.length > 0)
//        {
//            tbodytr.childNodes[i].style.width = width + "px";
//        }
//        if (this.badd)
//        {
//            tfoottr.childNodes[i].style.width = width + "px";//input
//            tfoottr.childNodes[i].firstChild.style.width = (width - 2) + "px";//input
//            tfoottr.childNodes[i].firstChild.style.display = "";//input
//        }
//    }
    
    if (this.totalcount != -1 || this.bpage==1)
    {
        elemPage.innerHTML = this.getPageHtml();
        elemPage.style.width = "30000px";
        elemPage.firstChild.style.width = elemPage.firstChild.offsetWidth + "px";
        elemPage.style.width = "auto";
        if (!div.CTNGDT)
        {
            div.CTNGDT = div.style.overflow;//存储overflow
        }
        elemBody.style.overflow = div.CTNGDT;
        elemPage.firstChild.style.margin = "0 auto";
        //elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight - 2 ) + "px";
    }
    
    elemBody.firstChild.style.width = (elemBody.firstChild.offsetWidth) + "px";
    elemBody.style.width = "auto";
    
    
    var tmp = div.style.width;
    div.style.width = "10px";
    div.style.width = tmp;
    elemBody.style.margin = "0 auto";
    this.resetFlow();
//    if (window.attachEvent)
//    {
//        window.attachEvent("onscroll", this.resetFlow(this));
//    }
//    else
//    {
//        var d = this;
//        window.addEventListener("scroll", resetFlow_LC.bind(d), false);
//    }
//    if (this.totalcount != -1 || this.bpage==1)
//    {
//        div.style.overflow = "hidden";
//        elemBody.style.width = (div.offsetWidth - 2 ) + "px";
//        //因为横的滚动条一出来，竖的也出来了
//        if (elemBody.offsetWidth < elemBody.firstChild.offsetWidth)
//        {
//            elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight - 18) + "px";
//        }
//    }
    //滚动条

//    var vHeight = elemBody.offsetHeight - div.offsetHeight;  
//      
//    var elemTable = elemBody.firstChild.cloneNode(false);
//    elemTable.appendChild(elemBody.firstChild.firstChild);//移动caption
//    elemTable.appendChild(elemBody.firstChild.firstChild);//移动thead
//    elemHead.appendChild(elemTable);
//    
//    
//    elemTable = elemTable.cloneNode(false);
//    elemTable.appendChild(elemBody.firstChild.lastChild);//移动tfoot
//    elemFoot.appendChild(elemTable);
    
//    if (vHeight > 0)
//    {alert(vHeight);
//        elemBody.style.height = (elemBody.offsetHeight - vHeight) + "px";
//        var elemSpace = document.createElement("div");
//        elemSpace.style.height = vHeight + "px";
//        div.appendChild(elemSpace);
//        div.onscroll = function()
//        {
//            for (var i = 0; i < this.childNodes.length -1; i++)
//            {
//                this.childNodes[i].style.top = this.scrollTop + "px";
//            }
//            this.childNodes[1].scrollTop = this.scrollTop + "px";
//        }
//    }
}


function resetFlow_LC()
{
    var div = this.$(this.listid);
    var elemBody = div.firstChild;
    var elemPage = div.lastChild;
    if (this.totalcount != -1 || this.bpage==1)
    {
        div.style.overflow = "hidden";
        elemBody.style.width = (div.offsetWidth - 2 ) + "px";
        if (div.offsetHeight < elemBody.firstChild.offsetHeight + elemPage.offsetHeight - 4)
        {
            //因为横的滚动条一出来，竖的也出来了
            if (elemBody.offsetWidth < elemBody.firstChild.offsetWidth)
            {
                elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight - 18) + "px";
            }
            else
            {
                //if (div.parentNode.offsetHeight < elemBody.firstChild.offsetHeight + 4)
                elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight - 2 ) + "px";
            }
        }
        else
        {
            //因为横的滚动条一出来，竖的也出来了(针对IE)
            if (elemBody.offsetWidth < elemBody.firstChild.offsetWidth && window.attachEvent)
            {
                if (div.style.height.indexOf("px") > -1)//已经给定高度
                {
                    elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight) + "px";
                }
                else
                {
                    elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight + 18) + "px";
                }
            }
            else
            {
                elemBody.style.height = (div.offsetHeight - elemPage.offsetHeight) + "px";
            }
        }
    }
    if (this.bfill && elemBody.offsetWidth > elemBody.firstChild.offsetWidth)
    {
        elemBody.firstChild.style.width = (elemBody.offsetWidth - 2) + "px";
    }
}

function getColHtml_LC()
{
    var htmlBuf = new Array();
    htmlBuf.push('<tr class="' + this.colstyle + '">');
    htmlBuf.push('<td ');
    htmlBuf.push(' id="' + this.listid + '_cmd"');
    htmlBuf.push(' style="display:none;"');
    htmlBuf.push('>');
    if (this.bcheck && !this.bscheck && this.ballcheck)
    {
        htmlBuf.push('<input type="checkbox"');
        htmlBuf.push(' onclick="' + this.listname + '.listCheckToggle(this)"');
        htmlBuf.push('/>');
    }
    else
    {
        htmlBuf.push('&nbsp;');
    }
    htmlBuf.push('</td>');
    for (var i = 0; i < this.arrCol.length; i++)
    {
        htmlBuf.push('<td');
        htmlBuf.push(' id="' + this.arrCol[i].id + '"');
        htmlBuf.push(' onmouseover="' + this.listname + '.colOver(this, ' + i + ');"');
        htmlBuf.push(' onmouseout="' + this.listname + '.colOut(this, ' + i + ');"');
        htmlBuf.push(' onclick="' + this.listname + '.colClick(event, ' + i + ');"');
        htmlBuf.push(' oncontextmenu="' + this.listname + '.colRClick(event, ' + i + ');"');
        htmlBuf.push(' ondblclick="' + this.listname + '.colDblClick(event, ' + i + ');"');
//        htmlBuf.push(' style="width:' + this.arrCol[i].maxsize + 'px;');
        htmlBuf.push(' style="');
        if (!this.arrCol[i].visible)
        {
            htmlBuf.push('display:none;');
        }
        htmlBuf.push('">');
        htmlBuf.push(this.arrCol[i].text);
        htmlBuf.push('</td>');
    }
    htmlBuf.push('</tr>');
    return htmlBuf.join("");
}
function getRowHtml_LC()
{
    var htmlBuf = new Array();
    for (var i = 0; i < this.arrRow.length; i++)
    {
        htmlBuf.push('<tr');
        htmlBuf.push(' id="' + this.arrRow[i].id + '"');
        if (i % 2)
        {
            htmlBuf.push(' class="' + this.drowstyle + '"');
        }
        else
        {
            htmlBuf.push(' class="' + this.srowstyle + '"');
        }
        htmlBuf.push(' onmouseover="' + this.listname + '.rowOver(this, ' + i + ');"');
        htmlBuf.push(' onmouseout="' + this.listname + '.rowOut(this, ' + i + ');"');
        htmlBuf.push(' onclick="' + this.listname + '.rowClick(event, ' + i + ');"');
        htmlBuf.push(' oncontextmenu="' + this.listname + '.rowRClick(event, ' + i + ');"');
        htmlBuf.push(' ondblclick="' + this.listname + '.rowDblClick(event, ' + i + ');"');
        htmlBuf.push('>');
        htmlBuf.push('<td style="display:none;">');
        htmlBuf.push('<input type="checkbox"');
        if (this.arrRow[i].bchecked)
        {
            htmlBuf.push(' checked="checked"');
        }
        htmlBuf.push(' id="' + this.listid + '_ckb_' + i + '"');
        htmlBuf.push(' onclick="' + this.listname + '.listCheck(this, ' + i + ')"');
        htmlBuf.push(' style="display:none;"/>');
        htmlBuf.push('<input type="button" value="编辑"');
        htmlBuf.push(' onclick="' + this.listname + '.listEdit(this, ' + i + ')"');
        htmlBuf.push(' style="display:none;"/>');
        htmlBuf.push('<input type="button" value="删除"');
        htmlBuf.push(' onclick="' + this.listname + '.listDel(this, ' + i + ')"');
        htmlBuf.push(' style="display:none;"/>');
        htmlBuf.push('</td>');
        var arrCell = this.arrRow[i].arrCell;
        for (var j = 0; j < arrCell.length; j++)
        {
            htmlBuf.push('<td');
            htmlBuf.push(' id="' + arrCell[j].id + '"');
            htmlBuf.push(' onclick="' + this.listname + '.cellClick(event, ' + i + ',' + j + ');"');
            htmlBuf.push(' oncontextmenu="' + this.listname + '.cellRClick(event, ' + i + ',' + j + ');"');
            htmlBuf.push(' ondblclick="' + this.listname + '.cellDblClick(event, ' + i + ',' + j + ');"');
            if (!this.arrCol[j].visible)
            {
                htmlBuf.push(' style="display:none;"');
            }
            htmlBuf.push('>');
            htmlBuf.push(arrCell[j].text); 
            htmlBuf.push('</td>'); 
        }
        htmlBuf.push('</tr>');
    }
    return htmlBuf.join("");
}

function getFootHtml_LC()
{
    var htmlBuf = new Array();
    htmlBuf.push('<tr');
    htmlBuf.push(' id="' + this.listid + '_add"');
    htmlBuf.push(' class="' + this.rowaddstyle + '"');
    htmlBuf.push(' style="display:none;"');
    htmlBuf.push('>');
    htmlBuf.push('<td>');
    htmlBuf.push('<input type="checkbox"');
    htmlBuf.push(' onclick="' + this.listname + '.listCheckToggle(this)"');
    htmlBuf.push(' style="display:none;"/>');
    htmlBuf.push('<input type="button" value="删除"');
    htmlBuf.push(' onclick="' + this.listname + '.listDelChecked()"');
    htmlBuf.push(' style="display:none;"/>');
    htmlBuf.push('<input type="button" value="添加"');
    htmlBuf.push(' onclick="' + this.listname + '.listAdd(this)"');
    htmlBuf.push('/>');
    htmlBuf.push('</td>');
    for (var i = 0; i < this.arrCol.length; i++)
    {
        if (this.arrCol[i].visible)
        {
            htmlBuf.push('<td>');
        }
        else
        {
            htmlBuf.push('<td style="display:none;">');
        }
        if (this.arrCol[i].inputtype == "select")
        {
            htmlBuf.push('<select');
            htmlBuf.push(' id="' + this.listid + '_add_' + i + '"');
//            htmlBuf.push(' style="width:' + (this.arrCol[i].maxsize*1 + 22) + 'px;"');
            htmlBuf.push(' style="display:none"');
            if (!this.arrCol[i].bedit)
            {
                htmlBuf.push(' disabled="disabled"');
            }
            htmlBuf.push('>');
            var arrOption = this.arrCol[i].arrOption;
            for (var j = 0; j < arrOption.length; j++)
            {
                if (arrOption[j].text == this.arrCol[i].addvalue)
                {
                    htmlBuf.push('<option value="' + arrOption[j].value + '" selected="selected">');
                }
                else
                {
                    htmlBuf.push('<option value="' + arrOption[j].value + '">');
                }
                htmlBuf.push(arrOption[j].text + '</option>');
            }
            htmlBuf.push('</select>');
        }
        else
        {
            htmlBuf.push('<input type="text"');
            htmlBuf.push(' id="' + this.listid + '_add_' + i + '"');
            htmlBuf.push(' value="' + this.arrCol[i].addvalue + '"');
            htmlBuf.push(' style="display:none"');
//            htmlBuf.push(' style="width:' + this.arrCol[i].maxsize + 'px;"/>');
            htmlBuf.push('/>');
        }
//        htmlBuf.push('<input type="text" value="" style="width:' + this.arrCol[i].maxsize + 'px;"/>');
//        htmlBuf.push('<input type="text" value=""/>');
        htmlBuf.push('</td>');
    }
    htmlBuf.push('</tr>');
    ///分页效果
//    if (this.totalcount != -1 || this.bpage==1)
//    {
//        if (this.totalpage == 0)
//        {
//            this.totalpage += 1;
//        }
//        else
//        {
//            this.totalpage = parseFloat(this.totalcount / this.pagesize);
//        }
//        this.totalpage = Math.ceil(this.totalpage)
//        htmlBuf.push('<tr');
//        htmlBuf.push(' id="' + this.listid + '_page"');
//        htmlBuf.push(' class="' + this.rowpagestyle + '"');
//       // htmlBuf.push(' style="display:none;"');
//        htmlBuf.push('>');
//        htmlBuf.push('<td colspan="' + (this.arrCol.length + 1) + '">');
//        htmlBuf.push('<a');
//        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(1);">首页</a>&nbsp;&nbsp;');
//        htmlBuf.push('<a');
//        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(' + (this.curpage - 1) + ');">上页</a>&nbsp;&nbsp;');
//        htmlBuf.push('<a');
//        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(' + (this.curpage + 1) + ');">下页</a>&nbsp;&nbsp;');
//        htmlBuf.push('<a');
//        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(' + this.totalpage + ');">尾页</a>&nbsp;&nbsp;');
//        htmlBuf.push('跳转至');
//        htmlBuf.push('<input type="text" size="3" value="' + this.curpage + '"');
//        htmlBuf.push(' id="' + this.listid + '_pagenum"/>&nbsp;&nbsp;');
//        htmlBuf.push('<a');
//        htmlBuf.push(' href="javascript:' + this.listname + '.goPage();">跳转</a>');
//        if (this.totalcount != -1)
//        {
//            htmlBuf.push('当前: ' + this.curpage + '/' + this.totalpage +'页 ');
//            htmlBuf.push('总记录数: ' + this.totalcount + '条 ');
//        }
//        else
//        {
//            htmlBuf.push('当前: ' + this.curpage +'页 ');
//        }
//        htmlBuf.push('</td>');
//        htmlBuf.push('</tr>');
//    }
    return htmlBuf.join("");
}
function getPageHtml_LC()
{
    var htmlBuf = new Array();
    this.totalpage = parseFloat(this.totalcount / this.pagesize);
    if (this.totalpage == 0)
    {
        this.totalpage += 1;
    }
    this.totalpage = Math.ceil(this.totalpage);
    htmlBuf.push('<table');
    htmlBuf.push(' class="' + this.tablestyle + '"');
    htmlBuf.push('>');
    htmlBuf.push('<tfoot>');
    htmlBuf.push('<tr');
    htmlBuf.push(' id="' + this.listid + '_page"');
    htmlBuf.push(' class="' + this.rowpagestyle + '"');
    htmlBuf.push('>');
    htmlBuf.push('<td>');
    if (this.curpage <= 1)
    {
        htmlBuf.push('<a');
        htmlBuf.push('>首页</a>&nbsp;&nbsp;');
        htmlBuf.push('<a');
        htmlBuf.push('>上页</a>&nbsp;&nbsp;');
    }
    else
    {
        htmlBuf.push('<a');
        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(1);">首页</a>&nbsp;&nbsp;');
        htmlBuf.push('<a');
        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(' + (this.curpage - 1) + ');">上页</a>&nbsp;&nbsp;');
    }
    if (this.totalcount <= this.curpage * this.pagesize)
    {
        htmlBuf.push('<a');
        htmlBuf.push('>下页</a>&nbsp;&nbsp;');
        htmlBuf.push('<a');
        htmlBuf.push('>尾页</a>&nbsp;&nbsp;');
    }
    else
    {
        htmlBuf.push('<a');
        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(' + (this.curpage + 1) + ');">下页</a>&nbsp;&nbsp;');
        htmlBuf.push('<a');
        htmlBuf.push(' href="javascript:' + this.listname + '.goPage(' + this.totalpage + ');">尾页</a>&nbsp;&nbsp;');
    }
    htmlBuf.push('跳转至');
    htmlBuf.push('<input type="text" size="3" value="' + this.curpage + '"');
    htmlBuf.push(' id="' + this.listid + '_pagenum"/>&nbsp;&nbsp;');
    htmlBuf.push('<a');
    htmlBuf.push(' href="javascript:' + this.listname + '.goPage();">跳转</a>');
    if (this.totalcount != -1)
    {
        htmlBuf.push('当前: ' + this.curpage + '/' + this.totalpage +'页 ');
        htmlBuf.push('总记录数: ' + this.totalcount + '条 ');
    }
    else
    {
        htmlBuf.push('当前: ' + this.curpage +'页 ');
    }
    htmlBuf.push('</td>');
    htmlBuf.push('</tr>');
    htmlBuf.push('</tfoot>');
    htmlBuf.push('</table>');
    return htmlBuf.join("");
}
function getListHtml_LC()
{
//    var tableWidth = 0;
//    for (var i = 0; i < this.arrCol.length; i++)
//    {
//        if (this.arrCol[i].visible)
//        {
//            tableWidth += this.arrCol[i].maxsize;
//        }
//    }
//    if (tableWidth < this.minsize)
//    {
//        tableWidth = this.minsize;
//    }
    var htmlBuf = new Array();
    htmlBuf.push('<table');
    htmlBuf.push(' id="' + this.getTableid() + '"');
    htmlBuf.push(' class="' + this.tablestyle + '"');
//    htmlBuf.push(' style="width:' + tableWidth + 'px;"');
    htmlBuf.push('>');
    htmlBuf.push('<caption');
    htmlBuf.push(' id="' + this.getCaptionid());
    htmlBuf.push(' class="' + this.captionstyle + '"');
    if (!this.caption)
    {
        htmlBuf.push(' style="display:none;"');
    }
    htmlBuf.push('>');
    htmlBuf.push(this.caption);
    htmlBuf.push('</caption>');
    htmlBuf.push('<thead id="' + this.listid + '_thead">');
    htmlBuf.push(this.getColHtml());
    htmlBuf.push('</thead>');
    htmlBuf.push('<tbody id="' + this.listid + '_tbody">');
    htmlBuf.push(this.getRowHtml());
    htmlBuf.push('</tbody>');
    htmlBuf.push('<tfoot id="' + this.listid + '_tfoot">');
    htmlBuf.push(this.getFootHtml());
    htmlBuf.push('</tfoot>');
    htmlBuf.push('</table>');
    return htmlBuf.join("");  
}

/////////////////解析部分/////////////
function insertXml_LC(xmlInfo, kind)
{
    var XmlVal = this.getXmlDoc();
    if (XmlVal == null)
    {
        this.showMsg("浏览器不支持XML");
        return false;
    }
    if (xmlInfo.indexOf("<?xml") == -1)
    {
        xmlInfo = "<?xml version='1.0' encoding='gb2312' ?> " + xmlInfo;
    }
    try
    {
        XmlVal.loadXML(xmlInfo);
    }
    catch (e)
    {
        this.showMsg("XML数据不合法！");
        return false;
    }
    if (!XmlVal)
    {
        this.showMsg("XML对象为空！");
        return false;
    }
    //清除空白节点
    this.clearSpace(XmlVal);
    if (XmlVal.childNodes.length < 1)
    {
        this.showMsg("数据不合法！");
        return false;
    }
    var rootNode = null;
    if (XmlVal.childNodes[0].nodeName != "xml")
    {
        rootNode = XmlVal.childNodes[0];
    }
    else if (XmlVal.childNodes.length > 1)
    {
        rootNode = XmlVal.childNodes[1];
    }
    return this.insertNode(rootNode, kind);
}

function insertNode_LC(rootNode, kind)
{
    
    var attrs = rootNode.attributes;
    //存储全局自定义属性(pagesize等)
    for (var i = 0; i < attrs.length; i++)
    {
        this[attrs[i].name] = attrs[i].value;
    }
    this["minsize"] = parseInt(this["minsize"]);
    this["totalcount"]   = parseInt(this["totalcount"]);
    this["pagesize"]= parseInt(this["pagesize"]);
    this["curpage"] = parseInt(this["curpage"]);
    this["bcheck"]  = parseInt(this["bcheck"]);
    this["bscheck"] = parseInt(this["bscheck"]);
    if (this["bscheck"])
    {
        this["bcheck"] = 1;
    }
    this["badd"]    = parseInt(this["badd"]);
    this["bedit"]   = parseInt(this["bedit"]);
    this["bdel"]    = parseInt(this["bdel"]);
    this["bpage"]    = parseInt(this["bpage"]);
    
    //清除空白节点
    this.clearSpace(rootNode);
    if (rootNode.childNodes.length < 1)
    {
        return;
    }
    var colNodes = rootNode.childNodes[0];
    this.clearSpace(colNodes);
    var arrColNode = colNodes.childNodes;//列数组


    var startRow = 0;//起始行数据


    //获取标题
    if (arrColNode.length == 0)
    {
        this.showMsg("找不到标题信息！");
        return false;
    }
    if (kind == 1)
    {
        for (var i = 0; i < arrColNode.length; i++)
        {
            var col = new ColInfo(this);
            attrs = arrColNode[i].attributes;
            //存储列自定义属性(visible等)
            for (var j = 0; j < attrs.length; j++)
            {
                col[attrs[j].name] = attrs[j].value;
            }
            col["visible"] = parseInt(col["visible"]);
//            col["maxsize"] = parseInt(col["maxsize"]);
            col["order"] = parseInt(col["order"]);
            col["id"] = this.getColid(i);
            col["text"] = this.$XML(arrColNode[i]);
            col["name"] = arrColNode[i].nodeName;
            
            col["inputtype"] = col["inputtype"].toLowerCase();
            if (arrColNode[i].childNodes.length > 1)
            {
                var selectNodes = arrColNode[i].childNodes[1];
                this.clearSpace(selectNodes);
                var lc = this;
                for (var j = 0; j < selectNodes.childNodes.length; j++)
                {
                    col["arrOption"].push({value:lc.$XML(selectNodes.childNodes[j],"value"),text:lc.$XML(selectNodes.childNodes[j])});
                }
            }
            
//            var cellSize = this.calTextSize(col["text"]);
//            if (cellSize > col["maxsize"])
//            {
//                col["maxsize"] = cellSize;
//            }
            this.arrCol.push(col);
        }
        startRow = 1;
    }
    else if(kind == 2)
    {
        for (var i = 0; i < arrColNode.length; i++)
        {
            var col = new ColInfo(this);
            col["id"] = this.getColid(i);
            col["text"] = arrColNode[i].nodeName;
//            var cellSize = this.calTextSize(col["text"]);
//            if (cellSize > col["maxsize"])
//            {
//                col["maxsize"] = cellSize;
//            }
            this.arrCol.push(col);
        }
    }
    else
    {
        this.showMsg("请输入数据格式类型");
        return;
    }
    var arrRowNode = rootNode.childNodes;//行数组


    for (var i = startRow; i < arrRowNode.length; i++)
    {
        var row = new RowInfo(this, this.getRowid(i - startRow));
        attrs = arrRowNode[i].attributes;
        //存储行自定义属性


        for (var j = 0; j < attrs.length; j++)
        {
            row[attrs[j].name] = attrs[j].value;
        }
        //清除空白节点
        this.clearSpace(arrRowNode[i]);
        var arrCellNode = arrRowNode[i].childNodes;
        for (var j = 0; j < arrCellNode.length; j++)
        {
            var cell = new CellInfo(row, this.getCellid(i - startRow, j));
            attrs = arrCellNode[j].attributes;
            //存储单元自定义属性


            for (var k = 0; k < attrs.length; k++)
            {
                cell[attrs[k].name] = attrs[k].value;
            }
            cell["text"] = this.$XML(arrCellNode[j]);
            //计算列宽
//            var cellSize = this.calTextSize(cell["text"]);
//            if (cellSize > this.arrCol[j].maxsize)
//            {
//                this.arrCol[j].maxsize = cellSize;
//            }
            row.append(cell);
        }
        row["bchecked"] = parseInt(row["bchecked"]);
        this.arrRow.push(row);
    }
    return true;
}

function calTextSize_LC(text)
{
    text = text.replace(/<\/?[^>]+>/gi, '');
    var strlen = 0;
    if (text)
    {
        for (var i = 0; i < text.length; i++)
        {
            if (text.charCodeAt(i) < 256)
            {
                strlen += 2/3;
            }
            else
            {
                strlen++;
            }
        }
    }
    return parseInt(this.fontsize * strlen + this.offset);
}
function reset_LC()
{
    var arrRow = this.arrRow;
    while(arrRow.length > 0)
    {
        arrRow.pop();
    }
    var arrCol = this.arrCol;
    while(arrCol.length > 0)
    {
        arrCol.pop();
    }
    this.xmlNode    = null;         //存储XML对象
    //根节点属性

    this.tablestyle = "listctrl";

    //内部使用
    this.oldrowstyle    = "";
    this.oldcolstyle    = "";
    this.selRow         = -1;
    this.selCol         = -1;
}

function $_LC(id)
{
    return this.doc.getElementById(id);
}

function $XML_LC(xmlNode, attrName, parseType)
{
    if (!xmlNode)
    {
        return null;
    }
    var vText = null;
    
    if (attrName)//取节点属性


    {
        vText = xmlNode.getAttribute(attrName);
    }
    else//取节点值


    {
        if (xmlNode.childNodes[0])
        {
            vText = xmlNode.childNodes[0].nodeValue;
        }
        else
        {
            vText = "";
        }
    }
    
    if (!parseType)
    {
        return vText;
    }
    if (parseType.toLowerCase() == "int")
    {
        return parseFloat(vText);
    }
    else if (parseType.toLowerCase() == "float")
    {
        return parseFloat(vText);
    }
    else
    {
        return vText;
    }
}
function getXmlDoc_LC()
{
    var XmlVal = null ;
    try
    {
        XmlVal = new ActiveXObject("Msxml2.DOMDocument.4.0") ;
    }
    catch(e)
    {
        try
        {
            XmlVal = new ActiveXObject("Microsoft.XMLDOM") ;
        }
        catch(o)
        {
            if(document.implementation 
                && document.implementation.createDocument
                && document.implementation.hasFeature("XPath", "3.0"))
            {
                XmlVal = document.implementation.createDocument('','',null);
                XmlVal.loadXML = function(xmlString)
                {
                    var childNodes = this.childNodes;
                    for (var i = childNodes.length - 1; i >= 0; i--)
                        this.removeChild(childNodes[i]);

                    var dp = new DOMParser();
                    var newDOM = dp.parseFromString(xmlString, "text/xml");
                    var newElt = this.importNode(newDOM.documentElement, true);
                    this.appendChild(newElt);
                }
            }
        }
    }
    
    return XmlVal;
}

function clearSpace_LC(elem)
{
    if(!elem.nodeType)
    {
        return;
    }
    for (var i = elem.childNodes.length - 1; i >= 0 ; i--)
    {
        if (elem.childNodes[i].nodeType != 1)
        {
            if (elem.childNodes[i].childNodes[0])
            {
                var text = elem.childNodes[i].childNodes[0].nodeValue;
                text = text.replace(new RegExp("(^[ \f\n\r\t\v]*)|([ \f\n\r\t\v]*$)","g"),"");
                if (!text)
                {
                    elem.removeChild(elem.childNodes[i]);
                }
            }
        }
    }
}